home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zbseq.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.3 KB  |  154 lines

  1. /* Copyright (C) 1990, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zbseq.c,v 1.4 2000/09/19 19:00:52 lpd Exp $ */
  20. /* Level 2 binary object sequence operators */
  21. #include "memory_.h"
  22. #include "ghost.h"
  23. #include "gxalloc.h"        /* for names_array in allocator */
  24. #include "oper.h"
  25. #include "ialloc.h"
  26. #include "istruct.h"
  27. #include "btoken.h"
  28. #include "store.h"
  29.  
  30. /*
  31.  * Define the structure that holds the t_*array ref for the system or
  32.  * user name table.
  33.  */
  34. typedef struct names_array_ref_s {
  35.     ref names;
  36. } names_array_ref_t;
  37. gs_private_st_ref_struct(st_names_array_ref, names_array_ref_t,
  38.              "names_array_ref_t");
  39.  
  40. /* Create a system or user name table (in the stable memory of mem). */
  41. int
  42. create_names_array(ref **ppnames, gs_memory_t *mem, client_name_t cname)
  43. {
  44.     ref *pnames = (ref *)
  45.     gs_alloc_struct(gs_memory_stable(mem), names_array_ref_t,
  46.             &st_names_array_ref, cname);
  47.  
  48.     if (pnames == 0)
  49.     return_error(e_VMerror);
  50.     make_empty_array(pnames, a_readonly);
  51.     *ppnames = pnames;
  52.     return 0;
  53. }
  54.  
  55. /* Initialize the binary token machinery. */
  56. private int
  57. zbseq_init(i_ctx_t *i_ctx_p)
  58. {
  59.     /* Initialize a fake system name table. */
  60.     /* PostScript code will install the real system name table. */
  61.     ref *psystem_names = 0;
  62.     int code = create_names_array(&psystem_names, imemory_global,
  63.                   "zbseq_init(system_names)");
  64.  
  65.     if (code < 0)
  66.     return code;
  67.     system_names_p = psystem_names;
  68.     return 0;
  69. }
  70.  
  71. /* <names> .installsystemnames - */
  72. private int
  73. zinstallsystemnames(i_ctx_t *i_ctx_p)
  74. {
  75.     os_ptr op = osp;
  76.  
  77.     if (r_space(op) != avm_global || imemory_save_level(iimemory_global) != 0)
  78.     return_error(e_invalidaccess);
  79.     check_read_type(*op, t_shortarray);
  80.     ref_assign_old(NULL, system_names_p, op, ".installsystemnames");
  81.     pop(1);
  82.     return 0;
  83. }
  84.  
  85. /* - currentobjectformat <int> */
  86. private int
  87. zcurrentobjectformat(i_ctx_t *i_ctx_p)
  88. {
  89.     os_ptr op = osp;
  90.  
  91.     push(1);
  92.     *op = ref_binary_object_format;
  93.     return 0;
  94. }
  95.  
  96. /* <int> setobjectformat - */
  97. private int
  98. zsetobjectformat(i_ctx_t *i_ctx_p)
  99. {
  100.     os_ptr op = osp;
  101.     ref cont;
  102.  
  103.     check_type(*op, t_integer);
  104.     if (op->value.intval < 0 || op->value.intval > 4)
  105.     return_error(e_rangecheck);
  106.     make_struct(&cont, avm_local, ref_binary_object_format_container);
  107.     ref_assign_old(&cont, &ref_binary_object_format, op, "setobjectformat");
  108.     pop(1);
  109.     return 0;
  110. }
  111.  
  112. /* <ref_offset> <char_offset> <obj> <string8> .bosobject */
  113. /*   <ref_offset'> <char_offset'> <string8> */
  114. /*
  115.  * This converts a single object to its binary object sequence
  116.  * representation, doing the dirty work of printobject and writeobject.
  117.  * (The main control is in PostScript code, so that we don't have to worry
  118.  * about interrupts or callouts in the middle of writing the various data
  119.  * items.)  Note that this may or may not modify the 'unused' field.
  120.  */
  121.  
  122. private int
  123. zbosobject(i_ctx_t *i_ctx_p)
  124. {
  125.     os_ptr op = osp;
  126.     int code;
  127.  
  128.     check_type(op[-3], t_integer);
  129.     check_type(op[-2], t_integer);
  130.     check_write_type(*op, t_string);
  131.     if (r_size(op) < 8)
  132.     return_error(e_rangecheck);
  133.     code = encode_binary_token(i_ctx_p, op - 1, &op[-3].value.intval,
  134.                    &op[-2].value.intval, op->value.bytes);
  135.     if (code < 0)
  136.     return code;
  137.     op[-1] = *op;
  138.     r_set_size(op - 1, 8);
  139.     pop(1);
  140.     return 0;
  141. }
  142.  
  143. /* ------ Initialization procedure ------ */
  144.  
  145. const op_def zbseq_l2_op_defs[] =
  146. {
  147.     op_def_begin_level2(),
  148.     {"1.installsystemnames", zinstallsystemnames},
  149.     {"0currentobjectformat", zcurrentobjectformat},
  150.     {"1setobjectformat", zsetobjectformat},
  151.     {"4.bosobject", zbosobject},
  152.     op_def_end(zbseq_init)
  153. };
  154.